<?php get_instance()->view('common/header');?>
<style type="text/css">
    .weui-picker__group:last-child{display:none !important;}
</style>
<body>
<?php if (!empty($list)):?>
    <div class="tablist bor_tt" style="padding-bottom: 4em">
        <div class="list">
            <?php foreach ($list as $k => $v):?>
                <div class="p3 bor_bb">
                    <div class="listitem heng vCenter p5_0">
                        <div class="">
                            <?php echo $v['title'].'('.$v['status_desc'].')'?>
                            <p class="f08 cor9"><?php echo $v['addtime']?></p>
                        </div>
                        <div class="">
                            <span class="dk tr"><?php echo $v['amount']?></span>
                        </div>
                    </div>
                </div>
            <?php endforeach;?>
        </div>
        <div class="weui-loadmore" style="display: none">
            <div class="load">
                <i class="weui-loading"></i>
                <span class="weui-loadmore__tips">正在加载</span>
            </div>
            <span class="noC" style="display: none">没有更多内容了~</span>
        </div>
    </div>
<?php else:?>
    <div class="statebox chuizhi jdjz" style="flex: 1;height: 100%;">
        <img class="stateimgda mb5" src="<?php echo $this->staticUrl?>img/default/4.png" alt="">
        <span class="f09 cor9 tc mb20">暂无余额记录</span>
    </div>
<?php endif;?>

    <div class="posbtnbox showDate">
        <a class="kbtn">选择日期</a>
    </div>
</body>
<script src="<?php echo $this->staticUrl?>js/jquery-weui.js"></script>
<script src="<?php echo $this->staticUrl?>js/base.js"></script>
<script type="text/javascript">
    $(function () {
        var page = 1;
        var loading = false;  //状态标记
        var time = '';
        $(document.body).infinite().on("infinite", function() {
            if(loading) return;
            loading = true;
            $(".weui-loadmore").show();
            $(".load").show();
            $(".noC").hide();
            page += 1;
            getList(1);
        });

        /**
         * 选择日期
         */
        $('.showDate').on('click', function () {
            var _this = $(this);
            weui.datePicker({
                start: 1990,
                end: new Date().getFullYear(),
                onChange: function (result) {
                    console.log(result);
                },
                onConfirm: function (result) {
                    time = result[0]+'-'+result[1];
                    page = 1;
                    _this.find('a').html(result[0]+'年'+result[1]+'月');
                    $(".noC").hide();
                    getList(0);
                }
            });
        });

        /**
         * 获取数据
         */
        function getList(t) {
            $.ajax('<?php echo getUrl('money/getBalanceLog');?>', {
                type:'post',
                data:{page:page,time:time},
                dataType:'json',
                error:function(){
                    show_message({status:0, message:'请求超时'});
                },
                timeout:60000,
                success:function(e,textStatus,jqXHR){
                    loading = false;
                    var html,
                        defaultImg = "<?php echo $this->staticUrl?>img/default/4.png";
                    if(t == 1){
                        if (!e.data.length){
                            $(document.body).destroyInfinite();
                            $(".load").hide();
                            $(".noC").show();
                            return;
                        }
                    }else{
                        if (!e.data.length){
                            $(".list").html('<div class="statebox chuizhi jdjz" style="flex: 1;height: 100%;">' +
                                '<img class="stateimgda mb5" src="'+defaultImg+'" alt="">' +
                                '<span class="f09 cor9 tc mb20">暂无余额记录</span></div>');
//                            $(".list").parent().removeClass('mt7');
                            return;
                        }else{
                            $(".list").html('');
                        }
                    }
//                    $(".list").parent().addClass('mt7');
                    $(".weui-loadmore").hide();
                    $.each(e.data, function (key, obj) {
                        html =
                            '<div class="p3 bor_bb">' +
                                '<div class="listitem heng vCenter p5_0">' +
                                    '<div class="">'+obj.title+'('+obj.status_desc+')' +
                                        '<p class="f08 cor9">'+obj.addtime+'</p>' +
                                    '</div>' +
                                    '<div class="">' +
                                        '<span class="dk tr">'+obj.amount+'</span>' +
                                    '</div>' +
                                '</div>' +
                            '</div>';
                        $(".list").append(html);
                    });
                }
            });
        }
    })
</script>
</html>